<template>
  <div>
<h2>注册功能</h2>
<table class="table table-bordered">
  <tr>
    <td>用户名</td>
    <td><input type="text" v-model="state.name"></td>
  </tr>
  <tr>
    <td>密码</td>
    <td><input type="password" v-model="state.pwd"></td>
  </tr>
  <tr>
    <td></td>
    <td><input type="button" value="注册" @click="register" class="btn btn-success"></td>
  </tr>
</table>
  </div>
</template>

<script setup lang="ts">
import {reactive,toRefs} from 'vue'
import axios from 'axios'
import {useRouter} from 'vue-router'
const router=useRouter()

const data=reactive({
  state:{
    name:'',
    pwd:''
  }
})

let {state} =toRefs(data)


const register=()=>{
  axios({
    url:'/api/Users/PostRegist',
    method:'post',
    data:{
      UL_Name:state.value.name,
      UL_Pwd:state.value.pwd
    }
  }).then(res=>{
    console.log(res);
    if(res.data.data==-1){
      alert("用户名已存在")
      return
    }
    if(res.data.data>0){
      alert("注册成功")
      router.push('/login')
    }else{
      alert("注册失败")
      return
    }
  }).catch(err=>{
    console.log(err);
  })
}






</script>

<style scoped>

</style>